package com.kxmall.web.controller.vehicle;

import com.kxmall.common.core.controller.BaseAppController;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.vehicle.domain.bo.KxVehicleBoxDownGoodsBo;
import com.kxmall.vehicle.domain.bo.KxVehicleBoxUpGoodsBo;
import com.kxmall.vehicle.domain.vo.KxVehicleInGoodsVo;
import com.kxmall.vehicle.domain.vo.KxVehicleVo;
import com.kxmall.web.controller.vehicle.service.IKxWebVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 运维人员-餐车管理
 */
@Api(tags = "运维人员-餐车管理")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vehicle/web")
public class KxWebVehicleController extends BaseAppController {

    private final IKxWebVehicleService iKxWebVehicleService;

    /**
     * 运维人员-获取餐车柜子里的商品信息
     */
    @GetMapping("/getVehicleBoxGoodsInfo")
    @ApiOperation(value = "/vehicle/web/getVehicleBoxGoodsInfo - 运维人员-获取餐车柜子里的商品信息", httpMethod = "GET")
    public R<KxVehicleVo> getVehicleBoxGoodsInfo(@NotNull(message = "餐车动力单元编号不能为空") String vehicleNo) {
        Long userId = getWebLoginUser().getUserId();
        String username = getWebLoginUser().getUsername();
        return R.ok(iKxWebVehicleService.getVehicleBoxGoodsInfo(vehicleNo,username));
    }

    /**
     * 运维人员-打开餐车柜格子
     */
    @GetMapping("/openVehicleBox")
    @ApiOperation(value = "/vehicle/web/openVehicleBox - 运维人员-打开餐车柜格子", httpMethod = "GET")
    public R<Boolean> openVehicleBox(@NotNull(message = "餐车动力单元编号不能为空") String vehicleNo,
                                     @NotNull(message = "车厢索引不能为空") Integer boxIndex) {
        Long userId = getWebLoginUser().getUserId();
        Boolean ret = iKxWebVehicleService.openVehicleBox(userId, vehicleNo, boxIndex);
        return  R.ok(ret);
    }

    /**
     * 获取分配给指定餐车点需要售卖的所有商品详情
     */
    @GetMapping("/getVehicleInGoods")
    @ApiOperation(value = "/vehicle/web/getVehicleInGoods - 运维人员-获取分配给指定餐车点需要售卖的所有商品详情", httpMethod = "GET")
    public R<List<KxVehicleInGoodsVo>> getVehicleInGoods(@NotNull(message = "餐车动力单元编号不能为空") String vehicleNo) {
        return R.ok(iKxWebVehicleService.getVehicleInGoods(vehicleNo));
    }

    /**
     * 给指定车辆柜格上架商品
     */
    @PostMapping("/vehicleBoxUpGoods")
    @ApiOperation(value = "/vehicle/web/vehicleBoxUpGoods - 运维人员-给指定车辆柜格上架商品", httpMethod = "POST")
    public R<Boolean> vehicleBoxUpGoods(@Validated(AddGroup.class) @RequestBody KxVehicleBoxUpGoodsBo bo) {
        Long userId = getWebLoginUser().getUserId();
        String username = getWebLoginUser().getUsername();
        return R.ok(iKxWebVehicleService.vehicleBoxUpGoods(userId, username, bo));
    }

    /**
     * 给指定车辆柜格上下架商品
     */
    @PostMapping("/vehicleBoxDownGoods")
    @ApiOperation(value = "/vehicle/web/vehicleBoxDownGoods - 运维人员-给指定车辆柜格下架商品", httpMethod = "POST")
    public R<Boolean> vehicleBoxUpDownGoods(@Validated(AddGroup.class) @RequestBody KxVehicleBoxDownGoodsBo bo) {
        Long userId = getWebLoginUser().getUserId();
        String username = getWebLoginUser().getUsername();
        return R.ok(iKxWebVehicleService.vehicleBoxDownGoods(userId, username, bo));
    }

}
